package model.util;

import java.sql.*;

/**
 * @author Ashin0013
 * @Date 2020/1/4 17:36
 */
public class JdbcUtils {
    private static String username = "root";
    private static String password = "abc123456";
    private static String url = "jdbc:mysql://cdb-2uk9sxxi.cd.tencentcdb.com:10028/infuser";



    /**
     *
     * 建立连接的方法
     * @throws SQLException
     */
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(url,username,password);
    }

    /**
     * 调用函数后释放资源的方法7
     * @param con
     * @param s
     * @param re
     */
    public static void close(Connection con, Statement s, ResultSet re){
        try{
            if(re!=null){
                re.close();
                re=null;
            }
            if(s!=null){
                s.close();
                s=null;
            }
            if(con!=null){
                con.close();
                con = null;
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
